package md.map;

import gu.ai.Astar;
import gu.common.Arrays;
import md.action.AIController;
import md.constants.FieldType;
import md.settings.Settings;

public class GameMap {
	
	public static int[] map;
	
	public final static int startPointX = Settings.mapWidth / 2;
	public final static int startPointY = 0;

	public final static int endPointX = Settings.mapWidth / 2;
	public final static int endPointY = Settings.mapHeight - 1;

	
	public final static int startPoint = calculateIndex(startPointX, startPointY);
	public final static int endPoint = calculateIndex(endPointX, endPointY);


	public static short[] defaultPath;
	
	public final static void init() {
		map = new int[Settings.mapLength];
		Arrays.fill(map, FieldType.EMPTY);
		
	
		calculateDefaultPath();
	}
	
	public final static void setValue(int x, int y, int v) {
		map[calculateIndex(x, y)] = v;
	}
	
	public final static int calculateIndex(int x, int y) {
		return x + y * Settings.mapWidth;
	}
	
	public final static int decodeX(int idx) {
		return idx % Settings.mapWidth;
	}
	
	public final static int decodeY(int idx) {
		return idx / Settings.mapWidth;
	}
	
	public final static void test() {
		setValue(24, 0, FieldType.WALL);
	}

	public final static void calculateDefaultPath() {
		defaultPath = AIController.findPath(startPointX, startPointY, endPointX, endPointY);
	}
	
}
